package com.example.bgmachine.bgmachine.sets;

import android.content.Context;
import android.graphics.Typeface;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.bgmachine.bgmachine.R;
import com.example.bgmachine.bgmachine.exts.CleanRecordData;
import com.example.bgmachine.bgmachine.homes.HomePages;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.LinkedList;

public class ClearMenuItemAdapter extends BaseAdapter {

    private Context mContext;
    private LinkedList<ClearMenuItemData> mData = new LinkedList<ClearMenuItemData>();

    public ClearMenuItemAdapter(Context context, LinkedList<ClearMenuItemData> list) {
        this.mContext = context;
        this.mData = list;
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    // txt_pin txt_content
    @Override
    public View getView(int position, View convertViewtms, ViewGroup parent) {
        ClearMenuItemAdapter.ViewHolder holder = null;
        if (convertViewtms == null) {
            View convertView = View.inflate(mContext, R.layout.frament_set_clear_list_item_content, null);
            convertViewtms = convertView;

            holder = new ClearMenuItemAdapter.ViewHolder();
            holder.mClearMenuItemData = mData.get(position);

            holder.frament_clear_list_content_bottom_btn_operation_click = convertViewtms.findViewById(R.id.frament_clear_list_content_bottom_btn_operation_click);
            holder.frament_clear_list_content_bottom_btn_operation_click.setTag(holder);

            holder.frament_clear_list_content_bottom_btn_operation_click.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {

                    ClearMenuItemAdapter.ViewHolder vs = (ClearMenuItemAdapter.ViewHolder) v.getTag();

                    if (vs == null) {
                        Log.d("aaa", " holder.mOrderContentData.getOrderNumber()==cc=");
                        return;
                    }
                    CleanRecordData.getCleanRecordData().setCleantimename( vs.mClearMenuItemData.getClearName() );
                    HomePages.mHomePages.setClearpupView(vs.mClearMenuItemData.getClearContent());
                }
            });
            holder.frament_clear_list_content_bottom_btn_operation_click.setText(holder.mClearMenuItemData.getClearName());
            convertView.setTag(holder);
        } else {

            holder = (ClearMenuItemAdapter.ViewHolder) convertViewtms.getTag();
            holder.mClearMenuItemData = mData.get(position);
            holder.frament_clear_list_content_bottom_btn_operation_click = convertViewtms.findViewById(R.id.frament_clear_list_content_bottom_btn_operation_click);
            holder.frament_clear_list_content_bottom_btn_operation_click.setTag(holder);
            holder.frament_clear_list_content_bottom_btn_operation_click.setText(holder.mClearMenuItemData.getClearName());


        }

        return convertViewtms;
    }

    //添加一个元素
    public void add(ClearMenuItemData data) {
        if (mData == null) {
            mData = new LinkedList<>();
        }
        mData.add(data);
        notifyDataSetChanged();
    }

    //往特定位置，添加一个元素
    public void add(int position, ClearMenuItemData data) {
        if (mData == null) {
            mData = new LinkedList<>();
        }
        mData.add(position, data);
        notifyDataSetChanged();
    }

    public void remove(ClearMenuItemData data) {
        if (mData != null) {
            mData.remove(data);
        }
        notifyDataSetChanged();
    }

    public void remove(int position) {
        if (mData != null) {
            mData.remove(position);
        }
        notifyDataSetChanged();
    }

    public void clear() {
        if (mData != null) {
            mData.clear();
        }
        notifyDataSetChanged();
    }


    private class ViewHolder {


        public Button frament_clear_list_content_bottom_btn_operation_click = null;
        public ClearMenuItemData mClearMenuItemData = null;

    }
}
